package com.dmz.workflow.controller;

import com.dmz.workflow.param.*;
import com.echronos.commons.Result;
import com.echronos.workflow.param.*;
import com.dmz.workflow.service.ProcessMatrixService;
import com.dmz.workflow.vo.ProcessMatrixMemberVO;
import com.dmz.workflow.vo.WorkflowMatrixVO;
import com.dmz.workflow.vo.WorkflowProcessMatrixVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 矩阵管理
 *
 * @author: zhouguoqing
 * @date: 2021/09/28/15:47
 */
@RequestMapping("/v1/flowable/matrix")
@Slf4j
@RestController
public class ProcessMatrixController {


    @Autowired
    private ProcessMatrixService processMatrixService;

    /**
     * 获取矩阵角色列表
     * @param companyId
     * @return
     */
    @GetMapping("/role/list")
    public Result<List<WorkflowProcessMatrixVO>> getMatrixRoleList(@RequestParam("companyId") Integer companyId) {
        return processMatrixService.getMatrixRoleList(companyId);
    }

    /**
     * 矩阵角色新增
     * @param param
     * @return
     */
    @PostMapping("/role/add")
    public Result<WorkflowProcessMatrixVO> addMatrixRole(@Valid @RequestBody AddMatrixRoleParam param) {
        return processMatrixService.addMatrixRole(param);
    }

    /**
     * 矩阵角色修改
     * @param param
     * @return
     */
    @PutMapping("/role/save")
    public Result<WorkflowProcessMatrixVO> saveMatrixRole(@Valid @RequestBody SaveMatrixRoleParam param) {
        return processMatrixService.saveMatrixRole(param);
    }

    /**
     * 获取矩阵角色维护
     * @param matrixId
     * @return
     */
    @GetMapping("/role/maintain/list")
    public Result<WorkflowMatrixVO> getMatrixRoleMaintainList(@RequestParam("matrixId") Integer matrixId) {
        return processMatrixService.getMatrixRoleMaintainList(matrixId);
    }

    /**
     * 保存矩阵角色维护
     * @param param
     * @return
     */
    @PutMapping("/role/maintain/save")
    public Result<WorkflowMatrixVO> saveMatrixRoleMaintain(@Valid @RequestBody SaveMatrixRoleMaintainParam param) {
        return processMatrixService.saveMatrixRoleMaintain(param);
    }

    /**
     * 获取矩阵人员维护
     * @param param
     * @return
     */
    @GetMapping("/people/maintain/list")
    public Result<List<ProcessMatrixMemberVO>> getMatrixPeopleMaintain(BaseMatrixPageParam param) {
        return processMatrixService.getMatrixPeopleMaintain(param);
    }

    /**
     * 新增矩阵人员维护
     * @param param
     * @return
     */
    @PostMapping("/people/maintain/add")
    public Result<ProcessMatrixMemberVO> addMatrixPeopleMaintain(@Valid @RequestBody AddMatrixPeopleMaintainParam param) {
        return processMatrixService.addMatrixPeopleMaintain(param);
    }

    /**
     * 矩阵人员维护保存
     * @param param
     * @return
     */
    @PutMapping("/people/maintain/save")
    public Result<ProcessMatrixMemberVO> saveMatrixPeopleMaintain(@Valid @RequestBody SaveMatrixPeopleMaintainParam param){
        return processMatrixService.saveMatrixPeopleMaintain(param);
    }

    /**
     * 矩阵人员维护删除
     * @param processMatrixIds 矩阵人员维护主键id集合
     * @return
     */
    @DeleteMapping("/people/maintain/delete")
    public Result<Boolean> deleteMatrixPeopleMaintain(@RequestParam("processMatrixIds") List<Integer> processMatrixIds){
        return processMatrixService.deleteMatrixPeopleMaintain(processMatrixIds);
    }

    /**
     * 根据矩阵主键id、角色名称获取该角色下的所有人员维护
     * @param matrixId
     * @param roleName
     * @return
     */
    @GetMapping("/role/people/maintain")
    public Result<List<PeopleMaintainMemberParam>> getMatrixRolePeopleMaintain(@RequestParam("matrixId") Integer matrixId,@RequestParam("roleName") String roleName){
        return processMatrixService.getMatrixRolePeopleMaintain(matrixId,roleName);
    }
}
